﻿using System;
using System.Collections.Generic;
using System.ServiceModel.DomainServices.Client;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
using NetBay.Core.Silverlight.Log;
using Rio.Applications.Web.Services;
using Rio.Framework.Pages.ModalControls;
using Rio.Framework.Localisation;

namespace Rio.Framework.Pages
{
    public partial class Message : UserControl
    {
        public event EventHandler Closed;

        public DialogResultTypes m_oDialogResult { get; set; }
        
        public Message(string p_szMessage, string p_szTitle = null, bool p_bTrace = true, Logger.Level p_eTraceLevel = Logger.Level.Debug, BitmapImage p_iImage = null, Boolean p_bOk = true, Boolean p_bCancel = false, Boolean p_bYes = false, Boolean p_bNo = false)
        {            
            m_oDialogResult = DialogResultTypes.UNKNOW;            

            if (p_bTrace == true)
            {
                //Logger.Write(p_szMessage, p_eTraceLevel);
            }

            InitializeComponent();
            InitLabel();
            if (p_bOk)
            {
                buttonOk.Visibility = Visibility.Visible;
                //get the focus
                this.Dispatcher.BeginInvoke(() => buttonOk.Focus());
                System.Windows.Browser.HtmlPage.Plugin.Focus();
            }
            if (p_bCancel)
            {
                buttonCancel.Visibility = Visibility.Visible;
            }
            if (p_bYes)
            {
                buttonYes.Visibility = Visibility.Visible;
                //get the focus
                this.Dispatcher.BeginInvoke(() => buttonYes.Focus());
                System.Windows.Browser.HtmlPage.Plugin.Focus();
            }
            if (p_bNo)
            {
                buttonNo.Visibility = Visibility.Visible;
            }

            if (p_iImage != null)
            {
                img.Source = p_iImage;
            }

            Title.Text = p_szTitle;

            Msg.Text = p_szMessage;
        }

        private void InitLabel()
        {
            buttonOk.Content = Resx.GetLabel(Constantes.k_OK);
            buttonCancel.Content = Resx.GetLabel(Constantes.k_CANCEL);
            buttonYes.Content = Resx.GetLabel(Constantes.k_YES);
            buttonNo.Content = Resx.GetLabel(Constantes.k_NO);
        }

        private void buttonOk_Click(object sender, RoutedEventArgs e)
        {            
            m_oDialogResult = DialogResultTypes.OK;
            Closed(sender, new EventArgs());
        }

        private void buttonCancel_Click(object sender, RoutedEventArgs e)
        {
            m_oDialogResult = DialogResultTypes.CANCEL;
            Closed(sender, new EventArgs());
        }

        private void buttonYes_Click(object sender, RoutedEventArgs e)
        {
            m_oDialogResult = DialogResultTypes.YES;
            Closed(sender, new EventArgs());
        }

        private void buttonNo_Click(object sender, RoutedEventArgs e)
        {
            m_oDialogResult = DialogResultTypes.NO;
            Closed(sender, new EventArgs());
        }


    }
}
